// mesh_3ds.h: interface for the mesh_3ds class.
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <vector>
#include "GePoint2.h"
#include "GePoint3.h"
#include "GePlaneT.h"
namespace ds3
{
	using namespace tge;
#pragma pack(push,2)
	struct mesh_3ds_face
	{
		WORD   vts[3];
		WORD   flags;
	public:
		bool isHiddenEdge(int i)const;
	};
#pragma pack(pop)
	class mesh_3ds_mat_map
	{
	public:
		mesh_3ds_mat_map* m_next;
	public:
		mesh_3ds_mat_map();
		~mesh_3ds_mat_map();
	public:
		void SetName(const TCHAR*tex);
		WORD* SetCountFace(long count);
	public:
		TCHAR      m_name[32];
		long      m_texid;
		long      m_countFace;
		WORD*     m_faces;
	};
	class decMesh3_create_pgn_data2;
	class decMesh3_pgn_uv_params;
	class mesh_3ds
	{
	public:
		mesh_3ds();
		~mesh_3ds();
	public:
		BOOL IsValid()const;
		void DestroyVerts();
		void AppendMatMap(mesh_3ds_mat_map*map);
		DWORD* SetCountSmoothGroup(long count);
		mesh_3ds_face* SetCountFace(long count);
		GeVector2f* SetCountUV(long count);
		void mem_free(void*p);
		void* mem_malloc(size_t size);
		GePoint3f* SetCountVertex(long countVts);
		bool search_loops(
			std::vector<int>&numFace,
			std::vector<int>&arrFace,
			std::vector<int>&numLoopPgn,
			std::vector<int>&arrLoopVertNum,
			std::vector<int>&arrLoopVert)const;
		bool search_loops2(
			int*&arrFacePgnIdx,
			decMesh3_pgn_uv_params*&uvPgn,
			decMesh3_create_pgn_data2*&pgn
			)const;
		bool is_co_plane(int face1, int face2)const;
	public:
		long              m_countVts;
		GePoint3f*        m_vts;
		long              m_countUV;
		GeVector2f*       m_uvs;
		long              m_countFace;
		mesh_3ds_face*    m_faces;
		long              m_countSmoothGroup;//==m_countFace
		DWORD*            m_smoothGroup;
		mesh_3ds_mat_map* m_mat_map;
	};
}
